package hy.mvpdemo.model.impl;

import java.util.ArrayList;
import java.util.List;

import hy.mvpdemo.model.NewsDataModelInterface;
import hy.mvpdemo.model.RequestResultListener;
import hy.mvpdemo.model.bean.NewsBean;
import hy.mvpdemo.model.util.ApiService;
import hy.mvpdemo.model.util.Retrofit2Util;
import hy.mvpdemo.presenter.impl.NewsDataPresenterImpl;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * 获取新闻列表实现类
 * Created by hy on 2016/10/23.
 */

public class NewsDataModelInterfaceImpl implements NewsDataModelInterface {

    private RequestResultListener requestListener;

    public NewsDataModelInterfaceImpl(NewsDataPresenterImpl newsDataPresenter) {
        requestListener = newsDataPresenter;
    }

    @Override
    public void getNewsData() {


            ApiService apiService = Retrofit2Util.getRetrofit(ApiService.NEWS_ROOT_LOADURL).create(ApiService.class);

            Call<NewsBean> newsBeanList = apiService.getNewsBeanList("30");
            newsBeanList.enqueue(new Callback<NewsBean>() {
                @Override
                public void onResponse(Call<NewsBean> call, Response<NewsBean> response) {
                    NewsBean body = response.body();

                    if(body.isStatus()){
                        requestListener.success(body.getTngou());
                    }else{
                        requestListener.fail("网络异常");
                    }



                }

                @Override
                public void onFailure(Call<NewsBean> call, Throwable t) {
                    requestListener.fail("网络异常");
                }
            });







    }

    @Override
    public String getNewsDataComment(int newid) {
        return null;
    }


}
